package cn.lg.soar.system.auth.entity;

import cn.lg.soar.common.data.tree.ITreeSource;
import cn.lg.soar.core.util.easyexcel.converters.BooleanConverter;
import cn.lg.soar.database.base.entity.NumberTreeEntity;
import cn.lg.soar.database.base.entity.TreeEntity;
import cn.lg.soar.system.api.handler.translate.TranslateByDict;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ExcelIgnoreUnannotated
@Getter
@Setter
@Accessors(chain = true)
@ApiModel(value = "menu对象", description = "菜单对象")
@TableName("lg_sys_menu")
public class Menu extends TreeEntity<Long> implements ITreeSource<Long> {

    private static final long serialVersionUID = 8162981465495525857L;

    @TableId
    private Long id;

    @TranslateByDict("MenuTypeEnum")
    @ExcelProperty(value = "类型(0按钮，1菜单，2目录，3系统)")
    private Integer type;

    @ColumnWidth(16)
    @ExcelProperty(value = "权限码")
    private String code;

    @ColumnWidth(16)
    @ExcelProperty(value = "路径")
    private String path;

    @ColumnWidth(16)
    @ExcelProperty(value = "重定向路径")
    private String redirect;

    @ColumnWidth(16)
    @ExcelProperty(value = "组件")
    private String component;

    @ColumnWidth(16)
    @ExcelProperty(value = "名称(标题)")
    private String title;

    @ExcelProperty(value = "图标")
    private String icon;

    @TranslateByDict("MenuStatusEnum")
    @ColumnWidth(10)
    @ExcelProperty(value = "状态：0正常，1隐藏菜单，2禁用菜单")
    private Integer status;

    @ExcelProperty(value = "是否隐藏子菜单", converter = BooleanConverter.class)
    private Boolean hideChildren;

    @ExcelProperty(value = "是否共享的", converter = BooleanConverter.class)
    private Boolean shared;

    @ExcelProperty(value = "是否缓存的", converter = BooleanConverter.class)
    private Boolean keepalive;

    @ExcelProperty(value = "备注")
    private String remark;

    @Version
    @ApiModelProperty(value = "乐观锁")
    protected Integer version;

    @ApiModelProperty(value = "排序")
    private Integer sort;

    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public Long getParentId() {
        return super.getParentId();
    }

    @Override
    public void setParentId(Long parentId) {
        super.setParentId(parentId);
    }

    @JsonIgnore
    @Override
    public Long primaryKey() {
        return this.id;
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        Menu menu = (Menu) o;
        return this.id.equals(menu.id);
    }

}
